<template>
  <div class="custom-form">
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px"
        :key="showFormKey">
        <el-col :span="24" v-if="hasFormPermission('user_id')">
          <el-form-item :label="$t('申请人ID')" prop="user_id">
            <xjr-select-user v-model="formData['user_id']"
              :disabled="hasDisabledPermission('user_id',false)" placeholder="请选择申请人ID" v-if="showForm"
              :userIds="formData.user_id"></xjr-select-user>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('user_name')">
          <el-form-item :label="$t('申请人名称')" prop="user_name">
            <el-input v-model="formData['user_name']" placeholder="请输入申请人名称"
              :disabled="hasDisabledPermission('user_name',false)"
              :readonly="!hasEditPermission('user_name',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('apply_time')">
          <el-form-item :label="$t('申请时间')" prop="apply_time">
            <el-date-picker :disabled="hasDisabledPermission('apply_time',false)"
              :readonly="!hasEditPermission('apply_time',false)" v-model="formData['apply_time']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择申请时间"
              clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('dept_id')">
          <el-form-item :label="$t('部门ID')" prop="dept_id">
            <avue-input-tree v-model="formData['dept_id']"
              :disabled="hasDisabledPermission('dept_id',false)" placeholder="系统默认(公司)部门ID" type="tree"
              :dic="dept_idOptions" :style="{width: '100%'}"></avue-input-tree>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('dept_name')">
          <el-form-item :label="$t('部门名称')" prop="dept_name">
            <el-input v-model="formData['dept_name']" placeholder="请输入部门名称"
              :disabled="hasDisabledPermission('dept_name',false)"
              :readonly="!hasEditPermission('dept_name',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('role_id')">
          <el-form-item :label="$t('角色ID')" prop="role_id">
            <el-input v-model="formData['role_id']" placeholder="请输入角色ID"
              :disabled="hasDisabledPermission('role_id',false)"
              :readonly="!hasEditPermission('role_id',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('role_name')">
          <el-form-item :label="$t('角色名称')" prop="role_name">
            <el-input v-model="formData['role_name']" placeholder="请输入角色名称"
              :disabled="hasDisabledPermission('role_name',false)"
              :readonly="!hasEditPermission('role_name',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('area')">
          <el-form-item :label="$t('地区')" prop="area">
            <el-input v-model="formData['area']" placeholder="请输入地区"
              :disabled="hasDisabledPermission('area',false)"
              :readonly="!hasEditPermission('area',false)" clearable :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('job_id')">
          <el-form-item :label="$t('职级ID')" prop="job_id">
            <el-input v-model="formData['job_id']" placeholder="请输入职级ID"
              :disabled="hasDisabledPermission('job_id',false)"
              :readonly="!hasEditPermission('job_id',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('job_name')">
          <el-form-item :label="$t('职级名称')" prop="job_name">
            <el-input v-model="formData['job_name']" placeholder="请输入职级名称"
              :disabled="hasDisabledPermission('job_name',false)"
              :readonly="!hasEditPermission('job_name',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('contract_name')">
          <el-form-item :label="$t('合同名称')" prop="contract_name">
            <el-input v-model="formData['contract_name']" placeholder="请输入合同名称"
              :disabled="hasDisabledPermission('contract_name',false)"
              :readonly="!hasEditPermission('contract_name',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('contract_body')">
          <el-form-item :label="$t('合同主体')" prop="contract_body">
            <el-select v-model="formData['contract_body']" placeholder="请选择合同主体"
              :disabled="hasDisabledPermission('contract_body',false)" filterable clearable
              :style="{width: '100%'}">
              <el-option v-for="(item, index) in contract_bodyOptions" :key="index" :label="item.F_ItemName"
                :value="item.F_ItemValue" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('contract_option')">
          <el-form-item :label="$t('合同选项')" prop="contract_option">
            <el-select v-model="formData['contract_option']" placeholder="请选择合同选项"
              :disabled="hasDisabledPermission('contract_option',false)" filterable clearable
              :style="{width: '100%'}">
              <el-option v-for="(item, index) in contract_optionOptions" :key="index" :label="item.F_ItemName"
                :value="item.F_ItemValue" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('contract_type')">
          <el-form-item :label="$t('合同类别')" prop="contract_type">
            <el-select v-model="formData['contract_type']" placeholder="请选择合同类别"
              :disabled="hasDisabledPermission('contract_type',false)" filterable clearable
              :style="{width: '100%'}">
              <el-option v-for="(item, index) in contract_typeOptions" :key="index" :label="item.F_ItemName"
                :value="item.F_ItemValue" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('remark')">
          <el-form-item :label="$t('合同说明')" prop="remark">
            <el-input v-model="formData['remark']" type="textarea" placeholder="请输入合同说明" :maxlength="2000"
              :disabled="hasDisabledPermission('remark',false)"
              :readonly="!hasEditPermission('remark',false)" :autosize="{minRows: 4, maxRows: 4}"
              :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('contract_number')">
          <el-form-item :label="$t('合同编号')" prop="contract_number">
            <el-input v-model="formData['contract_number']" placeholder="请联系运营中心-行政部-李博聪获取"
              :disabled="hasDisabledPermission('contract_number',false)"
              :readonly="!hasEditPermission('contract_number',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('project_name')">
          <el-form-item :label="$t('项目名称')" prop="project_name">
            <el-input v-model="formData['project_name']" placeholder="请输入项目名称"
              :disabled="hasDisabledPermission('project_name',false)"
              :readonly="!hasEditPermission('project_name',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('project_count')">
          <el-form-item :label="$t('项目数量')" prop="project_count">
            <el-input v-model="formData['project_count']" placeholder="请输入项目数量"
              :disabled="hasDisabledPermission('project_count',false)"
              :readonly="!hasEditPermission('project_count',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('project_type')">
          <el-form-item :label="$t('项目型号')" prop="project_type">
            <el-input v-model="formData['project_type']" placeholder="请输入项目型号"
              :disabled="hasDisabledPermission('project_type',false)"
              :readonly="!hasEditPermission('project_type',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('contract_amount')">
          <el-form-item :label="$t('合同金额')" prop="contract_amount">
            <el-input v-model="formData['contract_amount']" type="number" placeholder="请输入合同金额"
              :disabled="hasDisabledPermission('contract_amount',false)"
              :readonly="!hasEditPermission('contract_amount',false)" clearable :style="{width: '100%'}">
              <template slot="prepend">¥</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('payment_option')">
          <el-form-item :label="$t('付款方式')" prop="payment_option">
            <el-select v-model="formData['payment_option']" placeholder="请选择付款方式"
              :disabled="hasDisabledPermission('payment_option',false)" filterable clearable
              :style="{width: '100%'}">
              <el-option v-for="(item, index) in payment_optionOptions" :key="index" :label="item.F_ItemName"
                :value="item.F_ItemValue" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('signed_date')">
          <el-form-item :label="$t('签订日期')" prop="signed_date">
            <el-date-picker :disabled="hasDisabledPermission('signed_date',false)"
              :readonly="!hasEditPermission('signed_date',false)" v-model="formData['signed_date']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择签订日期"
              clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('delivery_date')">
          <el-form-item :label="$t('交付时间')" prop="delivery_date">
            <el-date-picker :disabled="hasDisabledPermission('delivery_date',false)"
              :readonly="!hasEditPermission('delivery_date',false)" v-model="formData['delivery_date']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择交付时间"
              clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('opposite_side_name')">
          <el-form-item :label="$t('对方名称')" prop="opposite_side_name">
            <el-input v-model="formData['opposite_side_name']" placeholder="请输入对方名称"
              :disabled="hasDisabledPermission('opposite_side_name',false)"
              :readonly="!hasEditPermission('opposite_side_name',false)" clearable
              :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('opposite_side_link_man')">
          <el-form-item :label="$t('对方联系人')" prop="opposite_side_link_man">
            <el-input v-model="formData['opposite_side_link_man']" placeholder="请输入供应商联系人及电话"
              :disabled="hasDisabledPermission('opposite_side_link_man',false)"
              :readonly="!hasEditPermission('opposite_side_link_man',false)" clearable
              :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('our_link_man')">
          <el-form-item :label="$t('我方联系人')" prop="our_link_man">
            <el-input v-model="formData['our_link_man']" placeholder="请输入我方联系人"
              :disabled="hasDisabledPermission('our_link_man',false)"
              :readonly="!hasEditPermission('our_link_man',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('contract_scan_file')">
          <el-form-item :label="$t('合同扫描件')" prop="contract_scan_file">
            <xjr-custom-upload :config="contract_scan_fileConfig"
              :disabled="hasDisabledPermission('contract_scan_file',false)"
              v-model="formData['contract_scan_file']" list-type="text"></xjr-custom-upload>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('contract_attached_file')">
          <el-form-item :label="$t('合同附件')" prop="contract_attached_file">
            <xjr-custom-upload :config="contract_attached_fileConfig"
              :disabled="hasDisabledPermission('contract_attached_file',false)"
              v-model="formData['contract_attached_file']" list-type="text"></xjr-custom-upload>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('F_IsEffective')">
          <el-form-item :label="$t('是否生效')" prop="F_IsEffective">
            <el-input v-model="formData['F_IsEffective']" placeholder="请输入是否生效"
              :disabled="hasDisabledPermission('F_IsEffective',false)"
              :readonly="!hasEditPermission('F_IsEffective',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasWorkFlowFormPermission('field129dcae')" v-show="optionsFlag">
          <el-form-item :label="$t('意见簿')" prop="field129dcae">
            <xjr-opinion-comonent :value="formData.field129dcae"></xjr-opinion-comonent>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="!isWorkflowForm">
          <el-form-item size="large" v-if="isEdit">
            <el-button type="primary" @click="submitForm" :loading="submitLoading">
              {{submitLoading?$t('workFlow.WFMenu.hintSubmit'):$t('submit')}}</el-button>
            <el-button @click="cancelForm">{{$t('cancelText')}}</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>

        import FilterableDataList from '@/components/generator/clientComponents/FilterableDataList.vue';
        import workflowFormAuthorize from "@/mixins/workflowFormAuthorize";
        import authorizeMixin from "@/mixins/authorize";
        import { baseUrl } from "@/config/env";
        import request from "@/router/axios";
        export default {
          mixins: [authorizeMixin,workflowFormAuthorize],
       
  components: {},
  props: ['keyValue', 'isEdit', 'disabled'],
  data() {
    let _this = this
    return {
      submitLoading: false,
      showForm: true,
      showFormKey: 1,
      reRenderSubform: false,
      operationVal: 'add',
      isAdd: true,
      addressUrl:'apply_contract',
      mainTableName: 'oa_contract_apply',
      formConfig: {},
      formData: {
        'user_id': '',
        'user_name': '',
        'apply_time': null,
        'dept_id': '',
        'dept_name': '',
        'role_id': '',
        'role_name': '',
        'area': '',
        'job_id': '',
        'job_name': '',
        'contract_name': '',
        'contract_body': '',
        'contract_option': '',
        'contract_type': '',
        'remark': '',
        'contract_number': '',
        'project_name': '',
        'project_count': '',
        'project_type': '',
        'contract_amount': "",
        'payment_option': '',
        'signed_date': null,
        'delivery_date': null,
        'opposite_side_name': '',
        'opposite_side_link_man': '',
        'our_link_man': '',
        'contract_scan_file': null,
        'contract_attached_file': null,
        'F_IsEffective': '',
        'field129dcae': null,
      },
      rules: {
        user_id: [],
        user_name: [{
          required: true,
          message: '请输入申请人名称',
          trigger: 'blur'
        }],
        apply_time: [{
          required: true,
          message: '请选择申请时间',
          trigger: 'change'
        }],
        dept_id: [],
        dept_name: [{
          required: true,
          message: '请输入部门名称',
          trigger: 'blur'
        }],
        role_id: [{
          required: true,
          message: '请输入角色ID',
          trigger: 'blur'
        }],
        role_name: [{
          required: true,
          message: '请输入角色名称',
          trigger: 'blur'
        }],
        area: [{
          required: true,
          message: '请输入地区',
          trigger: 'blur'
        }],
        job_id: [{
          required: true,
          message: '请输入职级ID',
          trigger: 'blur'
        }],
        job_name: [{
          required: true,
          message: '请输入职级名称',
          trigger: 'blur'
        }],
        contract_name: [{
          required: true,
          message: '请输入合同名称',
          trigger: 'blur'
        }],
        contract_body: [{
          required: true,
          message: '请选择合同主体',
          trigger: 'change'
        }],
        contract_option: [{
          required: true,
          message: '请选择合同选项',
          trigger: 'change'
        }],
        contract_type: [{
          required: true,
          message: '请选择合同类别',
          trigger: 'change'
        }],
        remark: [{
          required: true,
          message: '请输入合同说明',
          trigger: 'blur'
        }],
        contract_number: [{
          required: true,
          message: '请联系运营中心-行政部-李博聪获取',
          trigger: 'blur'
        }],
        project_name: [{
          required: true,
          message: '请输入项目名称',
          trigger: 'blur'
        }],
        project_count: [],
        project_type: [],
        contract_amount: [{
          required: true,
          message: '请输入合同金额',
          trigger: 'blur'
        }],
        payment_option: [{
          required: true,
          message: '请选择付款方式',
          trigger: 'change'
        }],
        signed_date: [{
          required: true,
          message: '请选择签订日期',
          trigger: 'change'
        }],
        delivery_date: [{
          required: true,
          message: '请选择交付时间',
          trigger: 'change'
        }],
        opposite_side_name: [{
          required: true,
          message: '请输入对方名称',
          trigger: 'blur'
        }],
        opposite_side_link_man: [],
        our_link_man: [],
        contract_scan_file: [{
          required: true,
          message: '合同扫描件不能为空',
          trigger: 'change'
        }],
        contract_attached_file: [{
          required: true,
          message: '合同附件不能为空',
          trigger: 'change'
        }],
        F_IsEffective: [],
      },
      user_idOptions: undefined,
      dept_idOptions: undefined,
      contract_bodyOptions: [],
      contract_optionOptions: [],
      contract_typeOptions: [],
      payment_optionOptions: [],
      contract_scan_fileConfig: {
        "showTip": true,
        "fileSize": 20,
        "sizeUnit": "MB",
        "buttonText": "点击上传",
        "disabled": false
      },
      contract_attached_fileConfig: {
        "showTip": true,
        "fileSize": 20,
        "sizeUnit": "MB",
        "buttonText": "点击上传",
        "disabled": false
      },
    }
  },
  computed: {},
  watch: {
    'formData.contract_amount': function(val, oldVal) {
      this.changeFormConfigDefaultValue();
    },
  },
  created() {
    this.formConfig = this.getFormConfig();
  },
  async mounted() {
    //TODO   再这里做数据回填 请求表单数据
   
           if(this.keyValue){
              this.isAdd = false;
          }
           if(!this.isAdd&&this.keyValue){
              this.operationVal = 'edit';
              try {
                let res = await request({
                  url: baseUrl + "/"+this.addressUrl+"/" + this.keyValue,
                  method: "get",
                });
                  
            this.formData = res.data.data
            
                 this.showFormKey++;
              } catch (error) {
              }
          }

       
    if (typeof this.getDept_idOptions == "function") {
      await this.getDept_idOptions();
    }
    if (typeof this.getContract_bodyOptions == "function") {
      await this.getContract_bodyOptions();
    }
    if (typeof this.getContract_optionOptions == "function") {
      await this.getContract_optionOptions();
    }
    if (typeof this.getContract_typeOptions == "function") {
      await this.getContract_typeOptions();
    }
    if (typeof this.getPayment_optionOptions == "function") {
      await this.getPayment_optionOptions();
    }
  },
  methods: {
    getFormData() {
      let key = this.mainTableName + 'Entity';
      let returnParams = {};
      returnParams[key] = this.formData;
      return {
        ...returnParams,
      };
    },
    validateForm() {
      this.$refs['elForm'].validate(valid => {});
    },
    async aysncValidateForm() {
      let validataArry = []
      validataArry.push(new Promise((resolve, reject) => {
        this.$refs['elForm'].validate(valid => {
          resolve(valid)
        })
      }))
      let res = await Promise.all(validataArry)
      if (res.includes(false)) {
        return false
      }
      else {
        return true;
      }
    },
    changeTableData() {},
    async submitForm() {
      this.submitLoading = true;
      let valid = await this.aysncValidateForm();
      if (valid == false) {
        this.submitLoading = false;
        return false;
      }
      this.changeTableData();
      //格式化数据
      let newObj = this.getFormData();
      
        //如果没有传入参数就是新增
        if (!this.keyValue) {

          request({
            url: baseUrl + "/"+this.addressUrl,
            method: "post",
            data : newObj
          }).then((res) => {
            this.submitLoading = false;
            this.$notify({
              title: "成功",
              message: "新增成功",
              type: "success",
            });
             this.$emit("onChange",true)
          });

        }
        else{

         request({
            url: baseUrl + "/"+this.addressUrl+"/" + this.keyValue,
            method: "put",
            data : newObj
          }).then((res) => {
            this.submitLoading = false;
            this.$notify({
              title: "成功",
              message: "修改成功",
              type: "success",
            });
             this.$emit("onChange",true)
          });

        }
       
       
      
    },
    cancelForm() {
      this.$emit("onChange", true)
    },
    formatTree(data, valueField, lableField, childField, type) {
      let tree = [];
      data.forEach((node, index) => {
        let newNode = {
          value: node[valueField],
          label: node[lableField],
        };
        if (type) {
          newNode.disabled = node[valueField] == undefined ? true : false
        }
        tree.push(newNode);
        if (node[childField] != null && node[childField].length > 0) {
          newNode.children = (this.formatTree(node[childField], valueField, lableField, childField,
          type));
        }
      }, this);
      return tree;
    },
    
          //辅助工作流 审批(编辑) 预留方法
          handleEdit() {
          },
          
    getNumberFixed2(number) {
      let splitNum = ("" + number).replace(/(^0*)/g, "").split(".");
      let num = splitNum[0] == "" ? '0' : splitNum[0];
      if (splitNum.length > 1) {
        num += '.';
        let roundNum = 2; //保留两位小数
        for (let i = 0; i < roundNum; i++) {
          num += splitNum[1][i];
        }
      }
      return parseFloat(num);
    },
    changeFormConfigDefaultValue() {
      let valueForFormIdMap = new Map();
      this.formConfig.fields.forEach((ele) => {
        if (ele.__config__.componentName == "table") {
          ele.__config__.children.forEach((element) => {
            valueForFormIdMap.set(ele.__config__.formId + "-table-" + element.__config__.formId,
              element.__config__.defaultValue);
          });
        }
        else if (ele.__config__.componentName && ele.__config__.componentName == 'avue-tabs') {
          let childrenObj = ele.__config__.childrenObj || {};
          let _arr = this.getValByTabs(childrenObj);
          _arr.map(item => {
            valueForFormIdMap.set(item.formId, item.defaultValue);
          });
        }
        else {
          valueForFormIdMap.set(ele.__config__.formId, this.formData[ele.__vModel__]);
        }
      });
      this.formConfig.fields.forEach((ele, index) => {
        if (ele.__config__.componentName == "table") {
          ele.__config__.children.forEach((element, childrenIndex) => {
            let defaultValue = 0;
            if (element.computationalConfiguration && element.computationalConfiguration.length > 0) {
              let formulaStr = "";
              element.computationalConfiguration.forEach((item) => {
                if (item.type == "taxRate") {
                  //税率
                  if (element.taxRate >= 0) {
                    formulaStr += element.taxRate * 0.01;
                  }
                }
                else {
                  let eleValue = valueForFormIdMap.get(item.formId) || 0;
                  formulaStr += item.formId == 0 ? item.name : eleValue;
                }
              });
              defaultValue = eval(formulaStr);
              defaultValue = this.getNumberFixed2(defaultValue);
              //大写
              if (element.isCapitalized) {
                this.formConfig.fields[index].__config__.children[childrenIndex].__config__
                  .capitalizedValue = this.getCapitalizedMethod(defaultValue);
              }
              this.formConfig.fields[index].__config__.children[childrenIndex].__config__
                .defaultValue = defaultValue;
              this.formData[element.__vModel__] = defaultValue;
            }
          });
        }
        else if (ele.__config__.componentName && ele.__config__.componentName == 'avue-tabs') {
          let childrenObj = ele.__config__.childrenObj || {};
          //avue-tabs
          this.calcDefaultValueByTabs(ele.__config__.childrenObj, valueForFormIdMap);
        }
        else {
          let defaultValue = 0;
          if (ele.computationalConfiguration && ele.computationalConfiguration.length > 0) {
            let formulaStr = "";
            ele.computationalConfiguration.forEach((item) => {
              if (item.type == "taxRate") {
                //税率
                if (ele.taxRate >= 0) {
                  formulaStr += ele.taxRate * 0.01;
                }
              }
              else {
                let eleValue = valueForFormIdMap.get(item.formId) || 0;
                formulaStr += item.formId == 0 ? item.name : eleValue;
              }
            });
            defaultValue = eval(formulaStr);
            defaultValue = this.getNumberFixed2(defaultValue);
            //大写
            if (ele.isCapitalized) {
              this.formConfig.fields[index].__config__.capitalizedValue = this.getCapitalizedMethod(
                defaultValue);
            }
            this.formConfig.fields[index].__config__.defaultValue = defaultValue;
            this.formData[ele.__vModel__] = defaultValue;
          }
        }
      });
    },
    getValByTabs(childrenObj) {
      let _arr = [];
      if (!childrenObj || !(childrenObj instanceof Object)) return [];
      for (let key in childrenObj) {
        let children = childrenObj[key];
        children.map(item => {
          if (item.__config__.componentName && item.__config__.componentName == 'avue-tabs') {
            let cObj = item.__config__.childrenObj || {};
            _arr.push(...this.getValByTabs(item.__config__.childrenObj));
          }
          else {
            let _obj = {};
            _obj.formId = item.__config__.formId;
            _obj.defaultValue = this.formData[item.__vModel__];
            _arr.push(_obj);
          }
        });
      }
      return (() => {
        return _arr;
      })()
    },
    calcDefaultValueByTabs(childrenObj, valueForFormIdMap) {
      if (!childrenObj || !(childrenObj instanceof Object)) return;
      for (let key in childrenObj) {
        let children = childrenObj[key];
        children.map(item => {
          if (item.__config__.componentName && item.__config__.componentName == 'avue-tabs') {
            let cObj = item.__config__.childrenObj || {};
            this.calcDefaultValueByTabs(cObj, valueForFormIdMap);
          }
          else {
            let defaultValue = 0;
            if (item.computationalConfiguration && item.computationalConfiguration.length > 0) {
              let formulaStr = "";
              item.computationalConfiguration.forEach((c) => {
                if (item.type == "taxRate") {
                  //税率
                  if (item.taxRate >= 0) {
                    formulaStr += item.taxRate * 0.01;
                  }
                }
                else {
                  let eleValue = valueForFormIdMap.get(c.formId) || 0;
                  formulaStr += c.formId == 0 ? c.name : eleValue;
                }
              });
              defaultValue = eval(formulaStr);
              defaultValue = this.getNumberFixed2(defaultValue);
              item.__config__.defaultValue = defaultValue;
              this.formData[item.__vModel__] = defaultValue;
            }
          }
        });
      }
    },
    async getDept_idOptions() {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/companies/departments/tree',
        });
        if (resp.data) {
          let {
            data
          } = resp.data
          this.dept_idOptions = this.formatTree(data, 'F_DepartmentId', 'F_FullName', 'children', 1);
        }
      }
      catch (error) {}
    },
    async getContract_bodyOptions() {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/data-items/htzt/detail',
        });
        if (resp.data.data) {
          this.contract_bodyOptions = resp.data.data;
        }
      }
      catch (error) {}
    },
    async getContract_optionOptions() {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/data-items/htxx/detail',
        });
        if (resp.data.data) {
          this.contract_optionOptions = resp.data.data;
        }
      }
      catch (error) {}
    },
    async getContract_typeOptions() {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/data-items/htnb/detail',
        });
        if (resp.data.data) {
          this.contract_typeOptions = resp.data.data;
        }
      }
      catch (error) {}
    },
    async getPayment_optionOptions() {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/data-items/fkfs/detail',
        });
        if (resp.data.data) {
          this.payment_optionOptions = resp.data.data;
        }
      }
      catch (error) {}
    },
    //子表单权限
    getAuthorityTableChildrenList(bindTable, children) {
      let column = [];
      if (bindTable && this.formEnCodeList && this.formEnCodeList[bindTable]) {
        let formSubEnCodeList = this.formEnCodeList[bindTable];
        if (children && children.length > 0) {
          column = children.map(ele2 => {
            if (formSubEnCodeList.includes(ele2.prop)) {
              ele2.hide = false;
            }
            else {
              ele2.hide = true;
            }
            if (ele2.hide == false) {
              //工作流中系统表单必填权限
              if (this.formSubTableNotRequiredList[bindTable] != undefined) {
                if (this.formSubTableNotRequiredList[bindTable].includes(ele2.prop)) {
                  ele2.required = false;
                }
                else {
                  ele2.required = true;
                }
              }
              ele2.rules = [];
              if (ele2.required) {
                ele2.rules = ele2.ruleList;
              }
              // disabled 属性
              if (this.formSubTableDisabledList[bindTable] != undefined) {
                if (this.formSubTableDisabledList[bindTable].includes(ele2.prop)) {
                  ele2.disabled = true;
                }
                else {
                  ele2.disabled = false;
                }
              }
            }
            return ele2;
          });
        }
        return column;
      }
      else {
        return children;
      }
    },
    getFormConfig() {
      let config = {
        "fields": [{
          "__vModel__": "user_id",
          "__type__": "user",
          "__organize__": true,
          "suffix-icon": "el-icon-setting",
          "__config__": {
            "label": "申请人ID",
            "showLabel": true,
            "tag": "xjr-select-user",
            "saveValue": "",
            "required": false,
            "span": 24,
            "bindTableField": "user_id",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 100,
            "fieldLength": "50",
            "bindTable": "oa_contract_apply",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "user_name",
          "__config__": {
            "label": "申请人名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 101,
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "user_name",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "date",
          "__vModel__": "apply_time",
          "__config__": {
            "label": "申请时间",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "defaultValue": null,
            "showLabel": true,
            "span": 24,
            "required": true,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 102,
            "fieldLength": "",
            "bindTableFieldType": "datetime",
            "bindTable": "oa_contract_apply",
            "bindTableField": "apply_time"
          }
        }, {
          "tempType": "tree",
          "__vModel__": "dept_id",
          "__type__": "department",
          "__organize__": true,
          "__config__": {
            "label": "部门ID",
            "showLabel": true,
            "required": false,
            "tag": "avue-input-tree",
            "dataKey": "data",
            "span": 24,
            "bindTableField": "dept_id",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 103,
            "fieldLength": "50",
            "bindTable": "oa_contract_apply",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "dept_name",
          "__config__": {
            "label": "部门名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 104,
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "dept_name",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "role_id",
          "__config__": {
            "label": "角色ID",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 105,
            "fieldLength": "50",
            "bindTable": "oa_contract_apply",
            "bindTableField": "role_id",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "role_name",
          "__config__": {
            "label": "角色名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 106,
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "role_name",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "area",
          "__config__": {
            "label": "地区",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 107,
            "fieldLength": "255",
            "bindTable": "oa_contract_apply",
            "bindTableField": "area",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "job_id",
          "__config__": {
            "label": "职级ID",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 108,
            "fieldLength": "50",
            "bindTable": "oa_contract_apply",
            "bindTableField": "job_id",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "job_name",
          "__config__": {
            "label": "职级名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 109,
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "job_name",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "contract_name",
          "__config__": {
            "label": "合同名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 110,
            "fieldLength": "255",
            "bindTable": "oa_contract_apply",
            "bindTableField": "contract_name",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "contract_body",
          "__config__": {
            "label": "合同主体",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "select",
            "span": 24,
            "required": true,
            "saveField": "",
            "showField": "",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 111,
            "dataType": "dataItem",
            "dataItem": "htzt",
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "contract_body",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "contract_option",
          "__config__": {
            "label": "合同选项",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "select",
            "span": 24,
            "required": true,
            "saveField": "",
            "showField": "",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 112,
            "dataType": "dataItem",
            "dataItem": "htxx",
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "contract_option",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "contract_type",
          "__config__": {
            "label": "合同类别",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "select",
            "span": 24,
            "required": true,
            "saveField": "",
            "showField": "",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 113,
            "dataType": "dataItem",
            "dataItem": "htnb",
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "contract_type",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "textarea",
          "__vModel__": "remark",
          "__config__": {
            "label": "合同说明",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "textarea",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 114,
            "fieldLength": 2000,
            "bindTable": "oa_contract_apply",
            "bindTableField": "remark",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "contract_number",
          "__config__": {
            "label": "合同编号",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 115,
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "contract_number",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "project_name",
          "__config__": {
            "label": "项目名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 116,
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "project_name",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "project_count",
          "__config__": {
            "label": "项目数量",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 117,
            "fieldLength": "",
            "bindTable": "oa_contract_apply",
            "bindTableField": "project_count",
            "bindTableFieldType": "int"
          }
        }, {
          "__vModel__": "project_type",
          "__config__": {
            "label": "项目型号",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 118,
            "fieldLength": "255",
            "bindTable": "oa_contract_apply",
            "bindTableField": "project_type",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "number",
          "__vModel__": "contract_amount",
          "computationalConfiguration": [],
          "prepend": "¥",
          "__config__": {
            "label": "合同金额",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input",
            "defaultValue": "",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 119,
            "fieldLength": "",
            "bindTable": "oa_contract_apply",
            "bindTableField": "contract_amount",
            "bindTableFieldType": "double"
          }
        }, {
          "__vModel__": "payment_option",
          "__config__": {
            "label": "付款方式",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "select",
            "span": 24,
            "required": true,
            "saveField": "",
            "showField": "",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 120,
            "dataType": "dataItem",
            "dataItem": "fkfs",
            "fieldLength": "100",
            "bindTable": "oa_contract_apply",
            "bindTableField": "payment_option",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "date",
          "__vModel__": "signed_date",
          "__config__": {
            "label": "签订日期",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "defaultValue": null,
            "showLabel": true,
            "span": 24,
            "required": true,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 121,
            "fieldLength": "",
            "bindTableFieldType": "datetime",
            "bindTable": "oa_contract_apply",
            "bindTableField": "signed_date"
          }
        }, {
          "tempType": "date",
          "__vModel__": "delivery_date",
          "__config__": {
            "label": "交付时间",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "defaultValue": null,
            "showLabel": true,
            "span": 24,
            "required": true,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 122,
            "fieldLength": "",
            "bindTableFieldType": "datetime",
            "bindTable": "oa_contract_apply",
            "bindTableField": "delivery_date"
          }
        }, {
          "__vModel__": "opposite_side_name",
          "__config__": {
            "label": "对方名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 123,
            "fieldLength": "255",
            "bindTable": "oa_contract_apply",
            "bindTableField": "opposite_side_name",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "opposite_side_link_man",
          "__config__": {
            "label": "对方联系人",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 124,
            "fieldLength": "255",
            "bindTable": "oa_contract_apply",
            "bindTableField": "opposite_side_link_man",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "our_link_man",
          "__config__": {
            "label": "我方联系人",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 125,
            "fieldLength": "255",
            "bindTable": "oa_contract_apply",
            "bindTableField": "our_link_man",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "contract_scan_file",
          "__config__": {
            "label": "合同扫描件",
            "tag": "el-upload",
            "avueType": "upload",
            "defaultValue": null,
            "showLabel": true,
            "required": true,
            "span": 24,
            "showTip": true,
            "buttonText": "点击上传",
            "fileSize": 20,
            "sizeUnit": "MB",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 126,
            "fieldLength": 2000,
            "bindTable": "oa_contract_apply",
            "bindTableField": "contract_scan_file",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "contract_attached_file",
          "__config__": {
            "label": "合同附件",
            "tag": "el-upload",
            "avueType": "upload",
            "defaultValue": null,
            "showLabel": true,
            "required": true,
            "span": 24,
            "showTip": true,
            "buttonText": "点击上传",
            "fileSize": 20,
            "sizeUnit": "MB",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 127,
            "fieldLength": 2000,
            "bindTable": "oa_contract_apply",
            "bindTableField": "contract_attached_file",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_IsEffective",
          "__config__": {
            "label": "是否生效",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 128,
            "fieldLength": "10",
            "bindTable": "oa_contract_apply",
            "bindTableField": "F_IsEffective",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "textarea",
          "__vModel__": "field129dcae",
          "__type__": "opinion",
          "__config__": {
            "label": "意见簿",
            "showLabel": true,
            "tag": "xjr-opinion-comonent",
            "defaultValue": null,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 129
          }
        }]
      };
      return config;
    },
  }
}

</script>
<style>
.el-table__empty-block {
  width: 100% !important;
}

.avue-form__row {
  padding: 0 !important;
}

#editorphone {
  width: 375px;
  margin: 0 auto;
  border: 1px solid #E4E7ED;
  padding: 0 7.5px;
  background: #f5f6fa;
  height: 700px;
  overflow-y: auto;
  overflow-x: hidden;
  border-radius: 5px;
}

#editorphone .el-col {
  border-bottom: 1px solid #F2F2F2;
  background: #fff;
  margin-bottom: 0;
  padding: 0 15px 6px !important;
  width: 100%;
}

#editorphone .el-form-item__label {
  line-height: 20px
}

#editorphone .el-input-group .el-input__inner {
  background: #f5f6fa
}

#editorphone .el-input__inner {
  border: 0
}

#editorphone .el-input-group__append,
#editorphone .el-input-group__prepend {
  border: 0;
  background: #edeef2;
  color: #666;
}

#editorphone .el-input-group .el-input__prefix {
  left: 44px
}

#editorphone .el-input-group .el-input__suffix {
  right: 44px
}

#editorphone .el-form-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-flow: wrap;
}

#editorphone .el-form-item__label {
  float: none;
  min-width: 85px;
  width: auto !important;
  text-align: left;
  flex: auto;
}

#editorphone .tinymce .el-form-item__label {
  min-width: 100%;
}

#editorphone .el-form-item__content {
  margin-left: 0px !important;
  flex: auto;
  width: calc(100% - 95px);
}

#editorphone .avueFormNoLable .el-form-item__label,
#editorphone .avueFormNoLable .avue-crud__pagination {
  display: none;
}

#editorphone .avueFormNoLable .el-collapse-item__wrap,
#editorphone .avueFormNoLable .el-collapse {
  border-bottom: 0
}

#editorphone .avueFormNoLable .el-col {
  border-bottom: 0;
  padding-bottom: 0
}

#editorphone .el-form-item__content .el-button:first-child {
  margin-left: 90px;
}

.el-upload__tip {
  line-height: 1.2;
}

</style>
